Skip to content

Conversation

@the-phinet
Copy link
Contributor

This was built and texted in the gzdoom repo, which seems to not be up-to-date. I hope everything works here.

I'm a little worried about the onTimer function being called from a background thread, instead of the event loop. I tried to implement with pushing events to the main thread, but for some reason I'm unable to receive user events.

@dpjudas
Copy link
Owner

dpjudas commented Jul 29, 2025

Just took a peek at SDL_AddTimer and it does indeed fire it from a worker thread. All the UI code assumes timer callbacks run on the UI thread, so for this to work safely the callback passed to SDL_AddTimer will have to then call SDL_PushEvent with a custom event.

If I understand SDL_PushEvent correctly, the event must first be registered using SDL_RegisterEvents. Then in the event loop where it checks all the other events it can then check for this custom event and dispatch it to a zwidget timer callback.

@the-phinet
Copy link
Contributor Author

Yeah, for some reason the event id I put in to the event (which comes from SDL_RegisterEvents), is different by 1 from the event that is received by the event loop. I'll take another crack at it today

@the-phinet
Copy link
Contributor Author

Ahh, figured it out. The event was being filtered by windowevent, so the only user event I was seeing was from paintevent. Paintevents just happen to be fired when I was expecting to see the timer event, so I got confused.

This was built and texted in the gzdoom repo, which seems to not be up-to-date. I hope everything works here
@dpjudas dpjudas merged commit 1de2249 into dpjudas:master Jul 29, 2025
1 of 2 checks passed
@the-phinet the-phinet mentioned this pull request Jul 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants